package com.allwees.data.analysis.usr.api;


import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.core.common.util.DateUtil;
import com.allwees.data.analysis.base.api.BaseAnalysisApi;
import com.allwees.data.analysis.usr.vo.UserStatisticsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/data/api/analysis/usr")
public class UserApi  extends BaseAnalysisApi {

    /**
     * 用户数据统计
     * @return
     */
    @GetMapping("/user_statistic_data")
    public R userStatisticData() {
        UserStatisticsVo userStatisticsVo = new UserStatisticsVo();
        Date dateTo = DateUtil.getPreDay(DateUtil.getDayLast(new Date()));
        //昨日新增注册数
        userStatisticsVo.setYesterdayUserRegNum(query("stat_common/USER_REG.txt",  DateUtil.addHour(dateTo,-24), dateTo));
        //累计注册人数
        userStatisticsVo.setTotalUserRegNum(query("stat_common/USER_REG.txt", DateUtil.getDate(2020,0,1), new Date()));
        //昨日交易用户数
        userStatisticsVo.setYesterdayUserPayedNum(query("stat_common/ORDER_PAY_USER_COUNT.txt", DateUtil.addHour(dateTo,-24),  dateTo));
        //累计交易用户数
        userStatisticsVo.setTotalUserPayedNum(query("stat_common/ORDER_PAY_USER_COUNT.txt", DateUtil.getDate(2020,0,1), new Date()));
        return  R.ok(userStatisticsVo);
    }

    /**
     * 累计注册人数
     * @return
     */
  /*  @GetMapping("/total_user_reg")
    public R totalUserReg() {
        Date dateFrom = DateUtil.getDate(2020,0,1);
        Date dateTo = new Date();
        return R.ok(query("stat_common/USER_REG.txt", dateFrom, dateTo));
    }*/

    /**
     * 昨日交易用户数
     * @return
     */
   /* @GetMapping("/yesterday_user_payed_num")
    public R yesterdayUserPayedNum() {
        //Date dateTo = DateUtil.getPreDay(DateUtil.getDayLast(new Date()));
        //Date dateFrom = DateUtil.addHour(dateTo,-24);
        Date dateFrom = DateUtil.addSeconds(new Date(), -600);
        Date dateTo = new Date();
        return R.ok(query("stat_common/ORDER_PAY_USER_COUNT.txt", dateFrom, dateTo));
    }*/

    /**
     * 累计交易用户数
     * @return
     */
    /*@GetMapping("/total_user_payed_num")
    public R totalUserPayedNum() {
        Date dateFrom = DateUtil.getDate(2020,0,1);
        Date dateTo = new Date();
        return R.ok(query("stat_common/ORDER_PAY_USER_COUNT.txt", dateFrom, dateTo));
    }*/


}
